package wt.hpad.activity.detail;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;

import com.daimajia.swipe.util.Attributes;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import wt.hpad.R;
import wt.hpad.activity.order.OrderActivity;
import wt.hpad.base.BaseFragment;
import wt.hpad.model.adapter.DishDetailAdapter;
import wt.hpad.model.bean.DishDetail;
import wt.hpad.utils.RCViewUtil;

/**
 * 显示 已下单 详情
 * Created by wt on 12.25.
 */

public class DetailFragment extends BaseFragment implements DetailContract.View {
    @BindView(R.id.rv_detail)
    RecyclerView rvDetail;
    @BindView(R.id.btn_detail_order)
    Button btnDetailOrder;
    Unbinder unbinder;
    DetailContract.Presenter mDetailPresenter;
    List<DishDetail> mDatas;
    private DishDetailAdapter mAdapter;

    @Override
    public void setPresenter(DetailContract.Presenter presenter) {
        mDetailPresenter = presenter;
        mDatas = mDetailPresenter.getDatas();
    }

    @Override
    public void closeCurrentActivity() {
        getActivity().finish();
    }

    @Override
    public void startOrderActivity() {
        startActivity(new Intent(getActivity(), OrderActivity.class));
    }

    @Override
    public void refreshRv() {
    }

    @Override
    public View initViews() {
        @SuppressLint("InflateParams") View view = LayoutInflater.from(baseActivity).inflate(R.layout.detail_frag, null);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void initData() {
        mDetailPresenter.subscribe();
        RCViewUtil.init_LinearLayout(rvDetail);


        mAdapter = new DishDetailAdapter(baseActivity, mDatas, getContext());
        mAdapter.setMode(Attributes.Mode.Single);
        rvDetail.setAdapter(mAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        mDatas.clear();
        mDatas = null;
        mAdapter.closeAllItems();
        mAdapter = null;
    }


    @OnClick(R.id.btn_detail_order)
    public void onViewClicked() {
        startOrderActivity();
        closeCurrentActivity();
    }
}
